"""
This file contains function for contoller for snakeAI.
"""

def gameController(event, snake):
    if event.keysym in ['Right', 'Down', 'Left', 'Up']:
        new_direction_idx = ['Right', 'Down', 'Left', 'Up'].index(event.keysym)
        if snake.getCurrentStatus() == 'alived' and abs(snake.getCurrentDirection() - new_direction_idx) != 2:
            snake.setCurrentDirection(new_direction_idx)
    elif event.keysym == 'space':
        if snake.getCurrentStatus() == 'paused':
            snake.setCurrentStatus('alived')
        elif snake.getCurrentStatus() == 'alived':
            snake.setCurrentStatus('paused')
    elif event.keysym == 'Return':
        snake.setCurrentStatus('paused')
        snake.refresh()
        snake.setCurrentStatus('alived')